package com.centling.smartSealForPhone.activity

import android.os.Bundle
import com.centling.smartSealForPhone.R
import com.centling.smartSealForPhone.constants.UrlConstants
import com.centling.smartSealForPhone.utils.OkHttpUtil
import com.centling.smartSealForPhone.utils.ShowToast
import com.google.gson.Gson
import kotlinx.android.synthetic.main.activity_msg_detail.*
import java.text.SimpleDateFormat
import java.util.*

class MessageDetailActivity : TitleBarActivity() {

    private val timeFormat = SimpleDateFormat("yyy-MM-dd HH:mm", Locale.CHINA)

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_msg_detail)

        setTitleBarText("通知详情")

        sendRequestToFetchApplySealApproval()
    }

    private fun sendRequestToFetchApplySealApproval() {
        mProcessDialog.setTitle("正在获取通知详情").showNormal()
        getEnqueue(String.format(Locale.CHINA, UrlConstants.FETCH_MSG_DETAIL, intent.getStringExtra("msg_id")
                ?: ""), object : OkHttpUtil.NetCallBack {
            override fun onSucceed(json: String?) {
                mProcessDialog.dismiss()

                val detailBean = Gson().fromJson(json, MsgDetailBean::class.java)
                tv_msg_detail_title.text = detailBean.title
                tv_msg_detail_time_under_title.text = timeFormat.format(Date(detailBean.creatTime))
                tv_msg_detail_digest.text = detailBean.msg
            }

            override fun onFailed(reason: String?) {
                mProcessDialog.dismiss()
                ShowToast.shortTime(reason)
                finish()
            }
        })
    }

    data class MsgDetailBean(var id: String, val msg: String, val title: String, val creatTime: Long)
}
